﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for ArticleData
/// </summary>
public class ArticleData
{
	public ArticleData()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public bool add(ArticlesEntities item)
    {
        bool flat = false;
        string[] pamamaters = { "@category_id","@name","@image","@summary","@content","@author","@status","@panel_id"};
        string[] values = { item._categoryID.ToString(), item._name, item._image,item._summary,item._content,item._author,item._status,item._panelID };
        if (Database.getExecProcedure("InsertArticle", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public bool edit(ArticlesEntities item)
    {
        bool flat = false;
        string[] pamamaters = { "@id", "@category_id", "@name", "@image", "@summary", "@content", "@status"};
        string[] values = {item._articlesID.ToString(), item._categoryID.ToString(), item._name, item._image, item._summary, item._content, item._status};
        if (Database.getExecProcedure("EdittArticle", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public bool updateVisited(int id)
    {
        bool flat = false;
        string[] pamamaters = { "@id" };
        string[] values = {id.ToString() };
        if (Database.getExecProcedure("EdittVisited", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }
    public bool delete(int id)
    {
        bool flat = false;
        string[] pamamaters = { "@id"};
        string[] values = {id.ToString() };
        if (Database.getExecProcedure("DeleteArticle", pamamaters, values) > 0)
        {
            flat = true;
        }
        else
        {
            flat = false;
        }
        return flat;
    }

    public DataTable getArticle(int id)
    {
        return Database.getTable("exec GetArticle '" + id.ToString() + "'");
    }

    public DataTable getArticle_panel(int panel_id)
    {
        return Database.getTable("exec getArticle_Panel '" + panel_id.ToString() + "'");
    }


    public DataTable getListArticle(int panel_id, string create_date, string file)
    {
        string[] paramaters = { "@create", "@file", "@p_id" };
        string[] values = { create_date, file, panel_id.ToString() };
        return Database.getTableProcedure("getListArticle", paramaters, values);
    }
}
